<?php

namespace app\admin\controller;

use app\admin\service\SliderService;
use support\spark\model\system\WebsiteSlider;
use support\Request;
use support\View;

class SliderController extends Curd
{


    public function index()
    {
        if (request()->isAjax()) {

            $sliderService = new SliderService();
            $list = $sliderService->getList(request()->all());
            return sparkSuccess($list);
        }
        return view('slider/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $sliderService = new SliderService();
            $res = $sliderService->addSlider($param);
            return sparkSuccess($res);
        }
        return view('slider/add');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $sliderService = new SliderService();
            $res = $sliderService->editSlider($param);
            return sparkSuccess($res);
        }

        $id = request()->input('id');
        $websiteSliderModel = new WebsiteSlider();
        View::assign([
            'info' => $websiteSliderModel->getInfoByWhere([
                'id' => $id
            ])
        ]);

        return view('slider/edit');
    }

    /**
     * 删除
     */
    public function del(Request $request)
    {
        $id = request()->input('id');

        $websiteSliderModel = new WebsiteSlider();
        $websiteSliderModel->delById($id);
        return $this->success(dataReturn(0,'删除成功'));
    }
}